package com.blog.until;

import java.util.Random;

/**
 * 主键处理工具类
 * 
 * @author HCK
 *
 */
public class RandomUtil {

    /**
     * 获取随机字母数字组合
     * 
     * @param length
     *            字符串长度
     */
    public static String getRandomCharAndNum(Integer length) {
        StringBuilder str = new StringBuilder();
        Random random = new Random();
        for (int i = 0; i < length; i++) {
            boolean b = random.nextBoolean();
            if (b) {
                // 字符串
                // 取得65个大写字母还是97小写字母
                str.append((char) (97 + random.nextInt(26)));
            } else { // 数字
                str.append(random.nextInt(10));
            }
        }
        return str.toString();
    }

}
